package server;

public class TopicBasedController extends Thread {
	
	private static final int ALONE_SLEEPING_PERIOD = 10000;
	private static final int NOT_ALONE_SLEEPING_PERIOD = 10000;

	private TopicBasedServer server;

	public TopicBasedController(TopicBasedServer server) {
		this.server = server;
	}

	public void run() {

		while(true){

			if(server.isAlone()){	
				try {	
					Thread.sleep(ALONE_SLEEPING_PERIOD);
					System.out.print(">> SERVER: alone \n");
				} catch (InterruptedException e) {	
					server.setIsAlone(false);
					System.out.print(">> SERVER: not alone anymore \n");
				}
			}
			else{
				try {
					Thread.sleep(NOT_ALONE_SLEEPING_PERIOD);
					server.setIsAlone(true);		
					System.out.print(">> SERVER: alone again \n");
				} catch (InterruptedException e){
					System.out.print(">> SERVER: not alone \n");
				}					
			}	
					
		}
	}
}
